<template>
	<div class="personal">
		<el-row :gutter="15">
			<!-- 基本信息 -->
			<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
				<el-card shadow="hover" class="mb15" header="基本信息">
					<div class="personal-user">
						<div class="personal-user-left">
							<el-upload class="personal-user-left-upload" action="" multiple :limit="1">
								<img v-if="userInfo.avatar" :src="userInfo.avatar" />
								<img v-else :src="avatar" />
							</el-upload>
						</div>
						<div class="personal-user-right">
							<el-form :model="userInfo" label-width="80px">
								<el-row>
									<el-col :span="24" class="personal-title mb18">{{ currentTime }}，{{ userInfo.userName }}</el-col>
									<el-col :span="24">
										<el-form-item label="登录名称" prop="loginName">
											<el-input v-model="userInfo.loginName" readonly></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="24">
										<el-form-item label="登录地址" prop="loginIp">
											<el-input v-model="userInfo.loginIp" readonly></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="24"  class="mb8">
										<el-form-item label="登录时间" prop="loginIp">
											<el-input v-model="userInfo.loginTime" readonly></el-input>
										</el-form-item>
									</el-col>
								</el-row>
							</el-form>
						</div>
					</div>
				</el-card>
			</el-col>

			<!-- 身份信息 -->
			<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
				<el-card shadow="hover" class="mb15" header="身份信息">
					<div class="personal-user">
						<div class="personal-user-right">
							<el-form :model="userInfo" label-width="80px">
								<el-row>
									<el-col :span="24">
										<el-form-item label="所在部门" prop="deptName">
											<el-input v-model="userInfo.dept.deptName" placeholder="所在部门" readonly></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="24">
										<el-form-item label="所属角色" prop="roleIds">
											<el-select v-model="userInfo.roleIds" multiple placeholder="所属角色" class="w100">
												<el-option
													v-for="item in userInfo.roles"
													:key="item.id"
													:label="item.roleName"
													:value="item.id">
												</el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="24">
										<el-form-item label="所在岗位" prop="postIds">
											<el-select v-model="userInfo.postIds" multiple  placeholder="所在岗位" class="w100">
												<el-option
													v-for="item in userInfo.posts"
													:key="item.id"
													:label="item.postName"
													:value="item.id">
												</el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="24">
										<el-form-item label="所处职级" prop="rankIds">
											<el-select v-model="userInfo.rankIds" multiple placeholder="所处职级" class="w100">
												<el-option
													v-for="item in userInfo.ranks"
													:key="item.id"
													:label="item.rankName"
													:value="item.id">
												</el-option>
											</el-select>
										</el-form-item>
									</el-col>
								</el-row>
							</el-form>
						</div>
					</div>
				</el-card>
			</el-col>
		</el-row>
		<el-row :gutter="15">
			<!-- 账号信息 -->
			<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
				<el-card shadow="hover" class="mb15" header="账号信息">
					<el-row :gutter="15" class="personal-recommend-row">
						<el-col :sm="6" class="personal-recommend-col">
							<div class="personal-recommend" style="background-color: #48D18D;">
								<i class="el-icon-lock" style="color: #64d89d;"></i>
								<div class="personal-recommend-auto">
									<div>账号安全 <el-button type="text" @click="onOpenEditPersonal('pwd')">立即修改</el-button></div>
									<div class="personal-recommend-msg">当前密码强度：强</div>
								</div>
							</div>
						</el-col>
						<el-col :sm="6" class="personal-recommend-col">
							<div class="personal-recommend" style="background-color: #F95959;">
								<i class="el-icon-mobile-phone" style="color: #F86C6B;"></i>
								<div class="personal-recommend-auto">
									<div>绑定手机 <el-button type="text" @click="onOpenEditPersonal('info')">立即修改</el-button></div>
									<div class="personal-recommend-msg">已绑定手机：{{ userInfo.phone }}</div>
								</div>
							</div>
						</el-col>
						<el-col :sm="6" class="personal-recommend-col">
							<div class="personal-recommend" style="background-color: #FEBB50;">
								<i class="el-icon-message" style="color: ##FDC566;"></i>
								<div class="personal-recommend-auto">
									<div>绑定邮箱 <el-button type="text" @click="onOpenEditPersonal('info')">立即修改</el-button></div>
									<div class="personal-recommend-msg">已绑定邮箱：{{ userInfo.email }}</div>
								</div>
							</div>
						</el-col>
						<el-col :sm="6" class="personal-recommend-col">
							<div class="personal-recommend" style="background-color: #8595F4;">
								<i class="el-icon-alarm-clock" style="color: #92A1F4;"></i>
								<div class="personal-recommend-auto">
									<div>当前时间 <el-button type="text"> </el-button></div>
									<div class="personal-recommend-msg">{{currentDate}}</div>
								</div>
							</div>
						</el-col>
					</el-row>
				</el-card>
			</el-col>
			
			<!-- 第三方账号账号信息 -->
			<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
				<el-card shadow="hover" class="mb15" header="第三方账号绑定">
					<SocialUser ref="socialUserRef"></SocialUser>
				</el-card>
			</el-col>
		</el-row>
		
		<EditPersonal ref="editPersonalRef" @submit="onRefreshCurrentTagsView"/>
	</div>
</template>

<script lang="ts">
import { ref, toRefs, reactive, computed, getCurrentInstance } from 'vue';
import { useRoute } from 'vue-router';
import { formatAxis, formatDate } from '/@/utils/formatTime';
import { Session } from '/@/utils/storage';
import EditPersonal from '/@/views/personal/editPersonal.vue';
import SocialUser from '/@/views/personal/social/user.vue';
export default {
	name: 'personal',
	components: { EditPersonal, SocialUser },
	setup() {
		const userInfo = Session.get('userInfo');
		const editPersonalRef = ref();
		const { proxy } = getCurrentInstance() as any;
		const route = useRoute();
		const publicUrl = import.meta.env.VITE_PUBLIC_PATH as string;
		const state = reactive({
			avatar: publicUrl + 'images/login/profile.png',
		});
		// 当前时间提示语
		const currentTime = computed(() => {
			return formatAxis(new Date());
		});
		
		// 当前日期
		const currentDate = computed(() => {
			return formatDate(new Date(), 'QQQQ WWW ZZZ yyyy-MM-dd HH:mm:ss');
		});

		// 修改个人信息
		const onOpenEditPersonal = (editType: string) =>{
			let row = {
				id: userInfo.id,
				loginName: userInfo.loginName,
				userName: userInfo.userName,
				phone: userInfo.phone,
				email: userInfo.email,
				editType: editType
			}
			editPersonalRef.value.openDialog(row);
		};

		const onRefreshCurrentTagsView = () => {
			proxy.mittBus.emit('onCurrentContextmenuClick', Object.assign({}, { contextMenuClickId: 0, ...route }));
		};
		
		return {
			editPersonalRef,
			currentTime,
			currentDate,
			userInfo,
			onOpenEditPersonal,
			onRefreshCurrentTagsView,
			...toRefs(state),
		};
	},
};
</script>

<style scoped lang="scss">
.personal {
	.personal-user {
		min-height: 120px;
		display: flex;
		align-items: center;
		.personal-user-left {
			min-height: 120px;
			border-radius: 3px;
			:deep(.el-upload) {
				height: 100%;
			}
			.personal-user-left-upload {
				height: 120px;
				img {
					width: 100%;
					height: 100%;
					border-radius: 3px;
				}
				&:hover {
					img {
						animation: logoAnimation 0.3s ease-in-out;
					}
				}
			}
		}
		.personal-user-right {
			flex: 1;
			padding: 0 15px;
			.personal-title {
				font-size: 18px;
			}
			.personal-item {
				display: flex;
				align-items: center;
				font-size: 13px;
				.personal-item-label {
					color: var(--el-text-color-secondary);
				}
				.personal-item-value {
				}
			}
		}
	}
	.personal-info {
		.personal-info-more {
			float: right;
			color: var(--el-text-color-secondary);
			font-size: 13px;
			&:hover {
				color: var(--color-primary);
				cursor: pointer;
			}
		}
		.personal-info-box {
			min-height: 120px;
			overflow: hidden;
			.personal-info-ul {
				list-style: none;
				.personal-info-li {
					font-size: 13px;
					padding-bottom: 10px;
					.personal-info-li-title {
						display: inline-block;
						color: var(--el-text-color-secondary);
						text-decoration: none;
					}
					& a:hover {
						color: var(--color-primary);
						cursor: pointer;
					}
				}
			}
		}
	}
	.personal-recommend-row {
		.personal-recommend-col {
			.personal-recommend {
				position: relative;
				height: 100px;
				color: var(--color-whites);
				border-radius: 3px;
				overflow: hidden;
				cursor: pointer;
				&:hover {
					i {
						right: 0px !important;
						bottom: 0px !important;
						transition: all ease 0.3s;
					}
				}
				i {
					position: absolute;
					right: -10px;
					bottom: -10px;
					font-size: 70px;
					transform: rotate(-30deg);
					transition: all ease 0.3s;
				}
				.personal-recommend-auto {
					padding: 15px;
					color: #FFFFFF;
					position: absolute;
					left: 0;
					top: 5%;
					.personal-recommend-msg {
						font-size: 12px;
						margin-top: 10px;
						color: #FFFFFF;
					}
				}
			}
		}
	}
	.personal-edit {
		.personal-edit-title {
			position: relative;
			padding-left: 10px;
			color: var(--el-text-color-regular);
			&::after {
				content: '';
				width: 2px;
				height: 10px;
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				background: var(--color-primary);
			}
		}
		.personal-edit-safe-box {
			border-bottom: 1px solid var(--el-border-color-light, #ebeef5);
			padding: 15px 0;
			.personal-edit-safe-item {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.personal-edit-safe-item-left {
					flex: 1;
					overflow: hidden;
					.personal-edit-safe-item-left-label {
						color: var(--el-text-color-regular);
						margin-bottom: 5px;
					}
					.personal-edit-safe-item-left-value {
						color: var(--el-text-color-secondary);
						margin-right: 15px;
					}
				}
			}
			&:last-of-type {
				padding-bottom: 0;
				border-bottom: none;
			}
		}
	}
}
</style>
